---
title: Measuring Climate Change Impacts on Agriculture: An Equilibrium Perspective on Supply-Side Approaches
subtitle: README for replication materials
author: Christophe Gouel
---

# Data Availability and Provenance Statements #

## Details on each Data Source ##

### FAOSTAT ###

I use various datasets from FAOSTAT (<http://www.fao.org/faostat/en>). Since,
there are no archive of past releases of FAOSTAT, I include these databases here
for replicability in accordance with the terms of use
(<http://www.fao.org/contact-us/terms/db-terms-of-use/en/>).

- `CommodityBalances_Crops_E_All_Data_(Normalized).zip` contains statistics on
  commodity balances from FAOSTAT, downloaded as bulk on May 31, 2017 from
  <http://www.fao.org/faostat/en/#data/BC>.
- `FAOSTAT-BC-Items-Definitions.csv` contains a mapping between balance sheet
  products and individual products, downloaded on June 2, 2017 from
  <http://www.fao.org/faostat/en/#data/BC>.
- `Inputs_Land_E_All_Data_(Normalized).zip` contains statistics on aggregated
  land use from FAOSTAT, downloaded as bulk on June 28, 2017 from
  <http://www.fao.org/faostat/en/#data/RL>.
- `Prices_E_All_Data_(Normalized).zip` contains statistics on producer prices
  from FAOSTAT, downloaded as bulk on June 2, 2017 from
  <http://www.fao.org/faostat/en/#data/PP>.
- `Production_Crops_E_All_Data_(Normalized).zip` contains statistics on crop
  production from FAOSTAT, downloaded as bulk on May 25, 2017 from
  <http://www.fao.org/faostat/en/#data/QC>.
- `Trade_DetailedTradeMatrix_E_All_Data_(Norm).zip` contains trade statistics
  from FAOSTAT, downloaded as bulk on May 31, 2017 from
  <http://www.fao.org/faostat/en/#data/TM>.
- `Value_of_Production_E_All_Data_(Normalized).zip` contains statistics on the
  value of agricultural production from FAOSTAT, downloaded as bulk on June 8,
  2017 from <http://www.fao.org/faostat/en/#data/QV>.

### GAEZ ###

Data of agro-ecological attainable yields from FAO/IIASA's GAEZ project v4.0
downloaded from <http://www.gaez.iiasa.ac.at>, except for grass which
corresponds to agro-climatically attainable yield. In the absence of stable DOI
for these data, I include these data here for replicability in accordance with
the terms of use (<https://gaez.fao.org/pages/disclaimer>).

### GTAP ###

I use GTAP data base version 9.2 for year 2011. Since it is now an old release,
it is freely available. Because it may not be easy to extract the required GTAP
files, I include them here in accordance with the terms of use
(<https://www.gtap.agecon.purdue.edu/databases/archives.asp>). GTAP data are
present here in two formats: the original `har` files in `data/gtap` and `gdx`
files in `output/gdx/calibration` because the conversion from `har` to `gdx` is
possible only on Windows.
 
### Hyde ###

The Hyde (History database of the Global Environment) database verson 3.2.1
provides geospatial information about crop and pasture land. The data are
automatically downloaded in the R code `src/data/hyde.R` from
<https://doi.org/10.24416/UU01-MO2FF3>.

## Dataset list ##

| Data file (folder `data`)                                     | Source  | Notes               | Provided |
|---------------------------------------------------------------|---------|---------------------|----------|
| `faostat/CommodityBalances_Crops_E_All_Data_(Normalized).zip` | FAOSTAT | As per terms of use | Yes      |
| `faostat/FAOSTAT-BC-Items-Definitions.csv`                    | FAOSTAT | As per terms of use | Yes      |
| `faostat/Inputs_Land_E_All_Data_(Normalized).zip`             | FAOSTAT | As per terms of use | Yes      |
| `faostat/Prices_E_All_Data_(Normalized).zip`                  | FAOSTAT | As per terms of use | Yes      |
| `faostat/Production_Crops_E_All_Data_(Normalized).zip`        | FAOSTAT | As per terms of use | Yes      |
| `faostat/Trade_DetailedTradeMatrix_E_All_Data_(Norm).zip`     | FAOSTAT | As per terms of use | Yes      |
| `faostat/Value_of_Production_E_All_Data_(Normalized).zip`     | FAOSTAT | As per terms of use | Yes      |
| `gaez4/various_folders                                        | FAO     | As per terms of use | Yes      |
| `gtap/gsddat.har`                                             | GTAP    | As per terms of use | Yes      |
| `gtap/gsdview.har`                                            | GTAP    | As per terms of use | Yes      |
| `hyde/baseline.zip`                                           | HYDE    | Stable DOI          | No       |
| `hyde/general_files.zip`                                      | HYDE    | Stable DOI          | No       |

# Files organization #

## Folders ##

    data/
    |-- faostat/
    |-- gaez4/
    |-- gtap/
    |-- hyde/
    |-- mappings/
    output/
    |-- figures/ Folder where R writes the figures.
      |-- sans/ Figures in sans-serif fonts.
      |-- serif/ Figures in serif fonts.
	|-- g00files/ g00 intermediary files for GAMS
	|-- gaez4/ Processed GAEZ files
	|-- gdx/ gdx files
	  |-- calibration/ For calibration
	  |-- results/ For results
    |-- log/ Log files from GAMS executions
	|-- lst/ Lst files from GAMS executions
    |-- tables/ Folder where R write the LaTeX tables.
    renv/ Folder with information about the R packages to restore.
    src/ Folder with the source code
	|-- data/ Code to treat data prior to simulations

## Association code and results ##

### Figures ###

| Program                 | Figure | File (folder `output/figures/serif`) |
|-------------------------|--------|--------------------------------------|
| `src/diagrams.R`        | 1      | `single-country`                     |
| `src/diagrams.R`        | 2      | `twocountry`                         |
| `src/diagrams.R`        | 3      | `twocrop1` and `twocrop2`            |
| `src/extract_results.R` | 4      | `main_sensi`                         |
| `src/extract_results.R` | A1     | `other_sensi`                        |

### Tables ###

| Program                         | Table | File (folder `output/tables`)     |
|---------------------------------|-------|-----------------------------------|
| `src/Two-country-pivotal.ipynb` | 1     | Included in the TeX file          |
| `src/diagrams.R`                | 2     | `two-crops`                       |
|                                 | 3     | Included in the TeX file          |
| `src/extract_results.R`         | 4     | `mainresults1` and `mainresults2` |
| Produced manually               | A1    | `mapCountries`                    |
| `src/extract_results.R`         | A2    | `yield_res`                       |
| `src/extract_results.R`         | A3    | `scenresults`                     |
| `src/extract_results.R`         | A4    | `marginal`                        |
| Produced manually               | A5    | `mapCrops`                        |
| `src/extract_results.R`         | A6    | `cdsresults1` and `cdsresults2`   |

# Dependencies #

The code has been tested on Linux (Ubuntu 18.04.6) and Windows 10/11 computers,
but not Mac.

## Software requirements ##

### Mandatory ###

- [GAMS](https://www.gams.com/) (code was last run with version 44.1.1)
    - Licenses for the solvers CONOPT4 and PATH are required.
	- GAMS folder should be present in the PATH environment variable (an option
      proposed under the advanced installation mode on Windows, but not on
      Linux). A `GAMSDIR` environment variable containing in its first element the
      path to GAMS folder should also be present (done by Windows installation
      with the PATH environment variable).
    - GAMS is used to simulate the model.
- [R](https://cran.r-project.org/) (code was last run with version 4.2.2)
    - On Windows, the restoration of old R packages is likely to require a prior
      installation of [Rtools](https://cran.r-project.org/bin/windows/Rtools/).
    - All the required R packages should be installed using the `renv` package
      which will restore the packages versions as used in the paper (and
      corresponding to R 4.2.2). To install everything, from the main directory,
      run in R:
	  
        renv::restore()

### Optional ###

- Python (code was last run with version 3.7.6)
    - The only used package is sympy (version 1.5.1).
    - Python is used to do the symbolic calculations related to section 2. It is
      not needed to replicate any of the results outside this section.
    - The calculations are available in the Jupyter notebooks (files `ipynb`) in
      the `src` folder.
- `unzip` UNIX command (so installed by default on Linux and Mac). On Windows,
  available from <http://gnuwin32.sourceforge.net/packages/unzip.htm>.
    - It is used in the data processing part to extract zipped data files. If
      the baseline data are not reconstructed, it is not necessary.

## Hardware requirements ##

The code was run on a server (Ubuntu 18.04.6) with 2 Intel processors Xeon
E5-2630 v3 2.40GHz (16 cores and 32 threads) and 64 Go of RAM. On this setup, it
takes about 1 day for running everything and requires 30Go of disk space.

The code can be run on a computer with fewer cores or less memory. However the
simulations for various climate scenarios are run in parallel to limit the
computing time, so the total time will be dependent on the number of cores. If
memory is not enough compared to the number of cores, the code may fail to
run. In this case, the solution is to decrease the number of workers that run in
parallel. To do this, in `src/.Rprofile` change the command `workers <-
availableCores()` to `workers <- nb_of_cores`.

# Instructions to Replicators #

No manual intervention is required, just run the master file `src/run_all.gms`
to replicate all the results. The master file is a GAMS file. It calls various R
and GAMS scripts, so to work it requires the executables `Rscript` and `gams` to
be available in the PATH.

The file `src/run_all.gms` contains at its beginning a switch (`data_prep`) to
select whether to run the data preparation part. If `data_prep` is equal to
`all` then all data preparation steps are run. This steps is not necessary
because the resulting data are included. If `data_prep` is equal to `gaez`, only
the preparation of the GAEZ yield data is done. This is the default value and
has to be run once before proceedings with the simulations because the GAEZ data
available in the `data/gaez4` folder cannot be directly used in the model. For
any other value, no data preparation is run.
